package com.yanshaohui.controller;

import com.yanshaohui.bean.Person;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * Created by TS-Ysh on 2018-05-11.
 */
@RestController
public class RestPersonController {

    @GetMapping("/person/{id}")
    public Person getOnePerson(@PathVariable("id") Long id){
        return new Person(id,"严少辉",1,"大寨路",35);
    }

    @GetMapping("/persons")
    public List<Person> getAllPerson(){
        return Arrays.asList(
                new Person(1L,"严少辉",1,"大寨路",35),
                new Person(2L,"谢晓亮",1,"丈八六路",34),
                new Person(3L,"冯楙",1,"恒大城",30));
    }

    /**
     * springmvcweb方式，和上面React方式比较一下性能
     * @param id
     * @return
     */
    @GetMapping("/person2/{id}")
    public Person getOnePerson2(@PathVariable("id") Long id){

        try {
            Thread.sleep(300);
            System.out.println("I am alive:" + System.currentTimeMillis());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return new Person(id,"严少辉",1,"大寨路",35);
    }
}
